package com.myh.configbean;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 莫耀华
 * @date 2020-08-24 10:05
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if(request.getSession().getAttribute("user")!=null) {
            return true;
        }
        request.getRequestDispatcher("/user/index.html").forward(request, response);
        return false;
    }
}
